package com.zmn.oms.services.impl.invoice;

import com.zmn.oms.model.entity.invoice.OrderInvoice;
import com.zmn.oms.persistence.interfaces.invoice.OrderInvoiceDao;
import com.zmn.oms.services.interfaces.invoice.OrderInvoiceService;
import io.shardingsphere.api.HintManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类描述：根据订单id集合查询订单发票
 *
 * @author lujia
 * @date 2018/11/28 15:56
 */
@Service
public class OrderInvoiceServiceImpl implements OrderInvoiceService {

    @Autowired
    private OrderInvoiceDao orderInvoiceDao;

    @Override
    public OrderInvoice findOrderInvoiceByKey(Long orderId) {
        return orderInvoiceDao.findOrderInvoiceByKey(orderId);
    }

    @Override
    public List<OrderInvoice> listOrderInvoiceByOrderIdList(List<Long> orderIdList) {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setMasterRouteOnly();
            return orderInvoiceDao.listOrderInvoiceByOrderIdList(orderIdList);
        }
    }

    @Override
    public void deleteOrderInvoiceByKey(Long orderId) {
        orderInvoiceDao.deleteOrderInvoiceByKey(orderId);
    }

    @Override
    public void insertOrderInvoice(OrderInvoice orderInvoice) {
        orderInvoiceDao.insertOrderInvoice(orderInvoice);
    }
}
